home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 343_02 / side.c < prev    next >
C/C++ Source or Header  |  1992-04-19  |  9KB  |  295 lines

  1.  
  2.        /***********************************************
  3.        *
  4.        *       file d:\cips\side.c
  5.        *
  6.        *       Functions: This file contains
  7.        *          main
  8.        *
  9.        *       Purpose:
  10.        *          This file contains the main calling
  11.        *          routine for a program which
  12.        *          takes two images and pastes them
  13.        *          together side by side or top to bottom
  14.        *          into a new image file.
  15.        *
  16.        *          There are three files: two input files
  17.        *          (file and file2), and one output
  18.        *          file (file3).
  19.        *
  20.        *       External Calls:
  21.        *          gin.c - get_image_name
  22.        *          numcvrt.c - get_integer
  23.        *                      int_convert
  24.        *          tiff.c - read_tiff_header
  25.        *          cutp.c - cut_image_piece
  26.        *                   paste_image_piece
  27.        *
  28.        *       Modifications:
  29.        *          19 April 1992 - created
  30.        *
  31.        *************************************************/
  32.  
  33. #include "d:\cips\cips.h"
  34.  
  35.  
  36.  
  37. short the_image[ROWS][COLS];
  38. short out_image[ROWS][COLS];
  39.  
  40. main(argc, argv)
  41.    int argc;
  42.    char *argv[];
  43. {
  44.  
  45.    char     method[80], name[80], name2[80], name3[80];
  46.    int      a, b, count, il, ie, ll, le,
  47.             il2, ie2, ll2, le2,
  48.             il3, ie3, ll3, le3,
  49.             length, length2, length3,
  50.             width, width2, width3;
  51.    struct   tiff_header_struct image_header,
  52.                                image_header2,
  53.                                image_header3;
  54.  
  55.    _setvideomode(_TEXTC80); /* MSC 6.0 statements */
  56.    _setbkcolor(1);
  57.    _settextcolor(7);
  58.    _clearscreen(_GCLEARSCREEN);
  59.  
  60.        /***********************************************
  61.        *
  62.        *       Interpret the command line parameters.
  63.        *
  64.        ************************************************/
  65.  
  66.    if(argc < 5 || argc > 5){
  67.     printf(
  68.      "\n"
  69.      "\n usage: side in-file-1 in-file-2 out-file method"
  70.      "\n        where method is Top-to-bottom or Side-by-side"
  71.      "\n");
  72.     exit(0);
  73.    }
  74.  
  75.    strcpy(name,   argv[1]);
  76.    strcpy(name2,  argv[2]);
  77.    strcpy(name3,  argv[3]);
  78.    strcpy(method, argv[4]);
  79.  
  80.    if(does_not_exist(name)){
  81.       printf("\nERROR: Input file %s does not exist", name);
  82.       printf(
  83.        "\n"
  84.        "\n usage: side in-file-1 in-file-2 out-file method"
  85.        "\n        where method is Top-to-bottom or Side-by-side"
  86.        "\n");
  87.       exit(2);
  88.    }
  89.  
  90.    if(does_not_exist(name2)){
  91.       printf("\nERROR: Input file %s does not exist", name2);
  92.       printf(
  93.        "\n"
  94.        "\n usage: side in-file-1 in-file-2 out-file method"
  95.        "\n        where method is Top-to-bottom or Side-by-side"
  96.        "\n");
  97.       exit(3);
  98.    }
  99.  
  100.    if(method[0] != 't'   &&
  101.       method[0] != 'T'   &&
  102.       method[0] != 's'   &&
  103.       method[0] != 'S'){
  104.       printf("\nERROR: Did not choose a valid method");
  105.       printf(
  106.        "\n"
  107.        "\n usage: side in-file-1 in-file-2 out-file method"
  108.        "\n        where method is Top-to-bottom or Side-by-side"
  109.        "\n");
  110.       exit(4);
  111.    }
  112.  
  113.        /***********************************************
  114.        *
  115.        *       Look at the headers of the two input
  116.        *       files.  The output file will hold
  117.        *       most of the two inputs.
  118.        *
  119.        *       Allocate the output file to hold both
  120.        *       input files no matter which is larger
  121.        *       in either dimension.
  122.        *
  123.        ************************************************/
  124.  
  125.    read_tiff_header(name, &image_header);
  126.    round_off_image_size(&image_header,
  127.                         &length, &width);
  128.    read_tiff_header(name2, &image_header2);
  129.    round_off_image_size(&image_header2,
  130.                         &length2, &width2);
  131.  
  132.    if(method[0] == 'T' || method[0] == 't'){
  133.       length3 = length + length2;
  134.       width3  = width;
  135.       if(width2 > width3) width3 = width2;
  136.    }
  137.    else{
  138.       width3  = width + width2;
  139.       length3 = length;
  140.       if(length2 > length3) length3 = length2;
  141.    }
  142.  
  143.    image_header3.image_length   = length3*ROWS;
  144.    image_header3.image_width    = width3*COLS;
  145.    image_header3.lsb            = 1;
  146.    image_header3.bits_per_pixel = 8;
  147.    image_header3.strip_offset   = 1000;
  148.    create_allocate_tiff_file(name3, &image_header3,
  149.                              out_image);
  150.  
  151.        /***********************************************
  152.        *
  153.        *   Loop through the two input images.  Cut
  154.        *   each image array from them and paste the
  155.        *   arrays into the output image.  Paste the
  156.        *   second input image to the left of the
  157.        *   first for the side by side option and
  158.        *   the second image below the first for the
  159.        *   top to bottom option.
  160.        *
  161.        ************************************************/
  162.  
  163.        
  164.        /***********************************************
  165.        *    
  166.        *   First do the side by side option.
  167.        *
  168.        ************************************************/
  169.  
  170.    if(method[0] == 'S' || method[0] == 's'){
  171.       il    = 1;
  172.       ie    = 1;
  173.       ll    = 101;
  174.       le    = 101;
  175.       count = 1;
  176.  
  177.              /****************************************
  178.              *    
  179.              *   Copy the first input file into the
  180.              *   left side of the output file.
  181.              *
  182.              *****************************************/
  183.  
  184.       for(a=0; a<length; a++){
  185.          for(b=0; b<width; b++){
  186.             printf("\ncut and paste %d of %d", 
  187.                      count++, length*width);
  188.             cut_image_piece(name, the_image,
  189.                             il+a*ROWS, ie+b*COLS,
  190.                             ll+a*ROWS, le+b*COLS);
  191.             paste_image_piece(name3, name, the_image, out_image,
  192.                             il+a*ROWS, ie+b*COLS,
  193.                             ll+a*ROWS, le+b*COLS);
  194.          }  /* ends loop over b */
  195.       }  /* ends loop over a */
  196.  
  197.       il2   = 1;
  198.       ie2   = 1;
  199.       ll2   = 101;
  200.       le2   = 101;
  201.       il3   = 1;
  202.       ie3   = 1+COLS*width;
  203.       ll3   = 101;
  204.       le3   = 101+COLS*width;
  205.       count = 1;
  206.  
  207.  
  208.              /****************************************
  209.              *    
  210.              *   Copy the second input file into the
  211.              *   right side of the output file.
  212.              *
  213.              *****************************************/
  214.  
  215.       for(a=0; a<length2; a++){
  216.          for(b=0; b<width2; b++){
  217.             printf("\ncut and paste %d of %d", 
  218.                      count++, length2*width2);
  219.             cut_image_piece(name2, the_image,
  220.                             il2+a*ROWS, ie2+b*COLS,
  221.                             ll2+a*ROWS, le2+b*COLS);
  222.             paste_image_piece(name3, name, the_image, out_image,
  223.                             il3+a*ROWS, ie3+b*COLS,
  224.                             ll3+a*ROWS, le3+b*COLS);
  225.          }  /* ends loop over b */
  226.       }  /* ends loop over a */
  227.    }  /* ends if side-by-side method */
  228.  
  229.        
  230.        /***********************************************
  231.        *    
  232.        *   Now do the top to bottom option.
  233.        *
  234.        ************************************************/
  235.  
  236.    if(method[0] == 'T' || method[0] == 't'){
  237.       il    = 1;
  238.       ie    = 1;
  239.       ll    = 101;
  240.       le    = 101;
  241.       count = 1;
  242.  
  243.              /****************************************
  244.              *    
  245.              *   Copy the first input file into the
  246.              *   top half of the output file.
  247.              *
  248.              *****************************************/
  249.  
  250.       for(a=0; a<length; a++){
  251.          for(b=0; b<width; b++){
  252.             printf("\ncut and paste %d of %d", 
  253.                      count++, length*width);
  254.             cut_image_piece(name, the_image,
  255.                             il+a*ROWS, ie+b*COLS,
  256.                             ll+a*ROWS, le+b*COLS);
  257.             paste_image_piece(name3, name, the_image, out_image,
  258.                             il+a*ROWS, ie+b*COLS,
  259.